home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Burning & Media
/
GB-PVR 1.2.13
/
GBPVR10213.msi
/
Cabs.w1.cab
/
Manage2.aspx.cs616
< prev
next >
Wrap
Text File
|
2008-04-10
|
24KB
|
547 lines
using System;
using System.Collections;
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Web.UI;
using System.Web.UI.WebControls;
using GBPVR.Public;
using GBPVRSchedule;
using gbweb.classes;
namespace gbweb
{
/// <summary>
/// Summary description for Manage.
/// </summary>
public partial class Manage2 : Page
{
private Settings guideParams;
protected string programUniqueIdentifier;
private string sortOrder;
private ArrayList sortOrders;
private int recordingTypeFilter;
private HttpCookie cookie;
protected ProgramTreeItem[] pgmTree;
protected int treeIdx;
private IList myScheduledRecordings;
private Channel channel;
private ArrayList displayScheduleSort = new ArrayList();
Hashtable channelCache = new Hashtable();
protected void Page_PreRender(object sender, System.EventArgs e)
{
//Call the common routine for loading the page with data
processViews();
if (mr_searchResults.SelectedValue == "tree")
{
hlDelete.Visible = false;
}
else
{
//Guest Users do not get access to initiatie, delete or cancel recordings.
if (Convert.ToBoolean((string)Session["NotGuestUser"]))
{
hlDelete.Visible = true;
}
else
{
hlDelete.Visible = false;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
#region Page Load code that is common to both the TreeView and TableView
Session["GuideStartTime"] = null;
guideParams = Global.Settings;
//Code to prevent Guest users from accessing the Admin and search Pages
if (!Convert.ToBoolean((string)Session["NotGuestUser"]))
{
NAV_SEARCH.Visible = false;
NAV_CONFIG.Visible = false;
}
treeIdx = 0;
pgmTree = new ProgramTreeItem[1000];
//Read in the recording filter settings from the cookie
cookie = Request.Cookies["recordingTypeFilter"]; ;
//Set the recording filters based off of what was found in the cookie
recordingTypeFilter = cookie != null ? Convert.ToInt32(cookie.Value) : 0xffbf;
//Check to see if the user selected the option for all filters or no filters and set the filter value accordingly
if (recordingTypes.SelectedValue == "all")
{
recordingTypeFilter = 65535;
//Set all the filter select boxes to true
for (int a = 0; a < recordingTypes.Items.Count; a++)
{
recordingTypes.Items[a].Selected = true;
}
//Uncheck the All and None options
recordingTypes.Items[0].Selected = false;
recordingTypes.Items[1].Selected = false;
}
else if (recordingTypes.SelectedValue == "none")
{
recordingTypeFilter = 65408;
//Set all the filter select boxes to false
for (int a = 0; a < recordingTypes.Items.Count; a++)
{
recordingTypes.Items[a].Selected = false;
}
}
checkRecordingType(ref recordingTypeFilter, "Pending", ScheduledRecording.STATUS_PENDING);
checkRecordingType(ref recordingTypeFilter, "In Progress", ScheduledRecording.STATUS_IN_PROGRESS);
checkRecordingType(ref recordingTypeFilter, "Available", ScheduledRecording.STATUS_COMPLETED);
checkRecordingType(ref recordingTypeFilter, "Failed", ScheduledRecording.STATUS_COMPLETED_WITH_ERROR);
checkRecordingType(ref recordingTypeFilter, "Conflict", ScheduledRecording.STATUS_CONFLICT);
checkRecordingType(ref recordingTypeFilter, "Reoccurring", ScheduledRecording.STATUS_PLACE_HOLDER);
checkRecordingType(ref recordingTypeFilter, "Deleted", ScheduledRecording.STATUS_DELETED);
//Update the cookie with what is found in the recording filters for the next display
cookie = new HttpCookie("recordingTypeFilter", recordingTypeFilter.ToString());
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
//Clear out the listings area so that you don't get leftovers from the previous display
CONTENTS.InnerHtml = "";
//Only execute on the first page load
if (!IsPostBack)
{
//Set the Day/date/time display on the header
viewDate.InnerText = DateTime.Now.ToLongDateString().Trim();
serverTime.InnerText = "Server Time: " + DateTime.Now.ToLongTimeString().Trim();
//Set the header tab of the Manage Recordings to active
NAV_RECORDINGS.Attributes.Add("class", "currentTab");
NAV_RECORDINGS.Visible = guideParams.showManage;
if (Convert.ToBoolean((string)Session["NotGuestUser"]))
{
NAV_SEARCH.Visible = guideParams.showSearch;
}
NAV_VIDEO.Visible = guideParams.showVideoLib;
NAV_MUSIC.Visible = guideParams.showMusicLib;
NAV_PHOTO.Visible = guideParams.showPhotoLib;
NAV_STATS.Visible = guideParams.showStats;
//Set the magic RSS links so IE and Firefox can sense the available RSS feeds
string url =
Request.Url.ToString().Replace(Request.Url.Scheme + Uri.SchemeDelimiter + Request.Url.Authority,
Request.Url.Scheme + Uri.SchemeDelimiter + Request.Headers["Host"]);
try
{
url = url.Substring(0, url.IndexOf("/gbpvr/"));
}
catch
{
url = url.Substring(0, url.IndexOf("/gbweb/"));
}
in_progressLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=in-progress");
completedLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=completed");
pendingLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=pending");
conflictLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=conflict");
failedLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=failed");
seasonLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=season");
deletedLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=deleted");
cookie = Request.Cookies["mr_showSearchResults"];
mr_searchResults.SelectedValue = cookie != null ? cookie.Value : "table";
//If the user has opted to use the TreeView search results allow the user to see the sort order
//options otherwise do not show them
if (mr_searchResults.SelectedValue == "tree")
{
treeControl.Visible = true;
sortResults.Visible = true;
sortResults2.Visible = true;
//If the user has ExtendedEWA then dynamicaly add a button for Star Rating sort
//and for original air date secondary sort
if (ExtendedEWA.Initialize())
{
ListItem starRating = new ListItem();
starRating.Text = "Star Rating";
starRating.Value = "mr_star";
srtOrder.Items.Add(starRating);
ListItem originalAirDate = new ListItem();
originalAirDate.Text = "Original Air Date (oad)";
originalAirDate.Value = "mr_original_date";
srtOrder.Items.Add(originalAirDate);
}
//Set the selected search order to whatever was used the last time
cookie = Request.Cookies["mr_SortOrder"];
srtOrder.SelectedValue = cookie != null ? cookie.Value : "mr_title";
cookie = Request.Cookies["mr_SecondarySortOrder"];
sec_srtOrder.SelectedValue = cookie != null ? cookie.Value : "mrs_title";
}
else
{
treeControl.Visible = false;
sortResults.Visible = false;
sortResults2.Visible = false;
}
}
else
{
//If the user has opted to use the TreeView search results allow the user to see the sort order
//options otherwise do not show them
if (mr_searchResults.SelectedValue == "tree")
{
sortResults.Visible = true;
sortResults2.Visible = true;
treeControl.Visible = true;
//Store the selected sort order in the cookie for the next search
cookie = new HttpCookie("mr_SortOrder", srtOrder.SelectedValue);
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
//Store the selected secondary sort order in the cookie for the next search
cookie = new HttpCookie("mr_SecondarySortOrder", sec_srtOrder.SelectedValue);
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
}
else
{
treeControl.Visible = false;
sortResults.Visible = false;
sortResults2.Visible = false;
}
//Store the selected display (table or tree) in the cookie for the next search
//
//Commented out the write of the cookie since we are only using a forced table view
//un-comment when TreeView is added back in
//
cookie = new HttpCookie("mr_showSearchResults", mr_searchResults.SelectedValue);
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
}
//Read the cookie for the sort order of the display
cookie = Request.Cookies["sortOrder"];
sortOrder = cookie != null ? cookie.Value.Trim(',') : "datetime,channel,title,status";
sortOrders = new ArrayList(sortOrder.Split(','));
string newSort = Request["sort"];
if (newSort != null)
{
if (sortOrders.Contains(newSort))
{
if (sortOrders[0].ToString() == newSort)
{
sortOrders.Remove(newSort);
sortOrders.Insert(0, newSort + " desc");
}
else
{
sortOrders.Remove(newSort);
sortOrders.Insert(0, newSort);
}
}
else
{
sortOrders.Remove(newSort + " desc");
sortOrders.Insert(0, newSort);
}
}
sortOrder = string.Join(",", (string[])sortOrders.ToArray(typeof(string)));
//Update the sort settings in the cookie for the next display
cookie = new HttpCookie("sortOrder", sortOrder);
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
//Store the selected display (table or tree) in the cookie for the next search
cookie = new HttpCookie("mr_showSearchResults", mr_searchResults.SelectedValue);
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
#endregion
FILTERS.Visible = true;
}
#region Page Load code for common processing of views - processViews
private void processViews()
{
//Turn on the appropriate display elements while turning off the one not being used
if (mr_searchResults.SelectedValue == "table")
{
RECORDINGS_HEADER.Visible = true;
SORT_HEADER.Visible = false;
}
else
{
forcedScrollbar.InnerHtml = "";
SORT_HEADER.Visible = true;
RECORDINGS_HEADER.Visible = false;
}
//Create a new schedulehelper object to process all the found recordings (all types)
Schedule scheduleHelper = Global.Schedule;
ProgrammeDisplay2 displayProgramme = new ProgrammeDisplay2();
//Remove a programme if someone clicked on Cancel prior t loading the list of programmes so that it is gone and does not appear again
string cancel = Request.Params["cancel"];
if ((cancel != null) && (cancel.Length > 0))
{
ScheduledRecording scheduledRecording = scheduleHelper.GetScheduledRecordingByOID(Convert.ToInt32(cancel));
if (scheduledRecording != null)
{
scheduleHelper.CancelScheduledRecording(scheduledRecording);
}
}
//Create a list of all of the recordings that are found
myScheduledRecordings = scheduleHelper.LoadRecordingSchedule();
//Verify that the object holding all of the recordings is an arraylist and if so sort it in the order the user has selected
//if (myScheduledRecordings is ArrayList)
// ((ArrayList)myScheduledRecordings).Sort(new RecordingComparer(sortOrders, channelCache));
//Verify the user has VLC installed by looking for it in the path that is set in the config
bool strmAllowed = File.Exists(Path.Combine(guideParams.strmVLCLoc, "vlc.exe"));
CSSProgrammeTableLoad tableLoad = new CSSProgrammeTableLoad();
Type pageType = Type.GetType("gbweb.Manage2");
displayScheduleSort = new ArrayList();
//Iterate through each recording to load it to the appropriate display format
foreach (ScheduledRecording scheduledRecording in myScheduledRecordings)
{
//Determine the status of the currect scheduled programme
int flag = (int) Math.Pow(2, scheduledRecording.getRecordingStatus());
//If the recording status of the current scheduled programme does not match the recording filter then we do not need to look at this schedule
//so we jump out of the foreach loop
if ((recordingTypeFilter & flag) == 0) continue;
//Instantiate a programme object for this schedule
Programme programme = scheduledRecording.getProgramme();
channel = scheduleHelper.GetChannelByOID(scheduledRecording.getChannelOID());
//Call the appropriate method for completing the processing of the view
if (mr_searchResults.SelectedValue == "table")
{
//We load the programme from the scheduled recording to an array so that we can sort them into the correct order after we have all
//the programs from all the recordings
displayScheduleSort.Add(scheduledRecording);
//tableLoad.processTable(pageType, channelCache, sortOrders, Cache, Request, Server, displayProgramme, strmAllowed, programme, scheduledRecording, false);
}
else
{
processTree(displayProgramme, programme, scheduledRecording);
}
}
if (mr_searchResults.SelectedValue == "tree")
{
//Resize the array of ProgrammeTreeItems so that is isn't hogging up space.
Array.Resize(ref pgmTree, treeIdx);
//TreeView1.CollapseAll();
TreeView1.Nodes.Clear();
//TreeView1.SelectedNode.CollapseAll();
TreeView1.Dispose();
//Fill the TreView Control with all the nodes in the correct format
displayProgramme.FillProgrammeTree(TreeView1, pgmTree, srtOrder.SelectedValue, sec_srtOrder.SelectedValue);
displayProgramme.Dispose();
}
else
{
//Sort the matching programmes into the choosen sort order
tableLoad.sortDisplay(sortOrders, displayScheduleSort, true);
//Format the now sorted matching results into the CSS table format
IDictionary knownRecordings = scheduleHelper.LoadKnownRecordings();
while (displayScheduleSort.Count > 0)
{
ScheduledRecording scheduledRecording = (ScheduledRecording) displayScheduleSort[0];
Programme pgm = scheduledRecording.getProgramme();
tableLoad.processTable(pageType, sortOrders, Cache, Request, Server, displayProgramme, strmAllowed, pgm, scheduledRecording, false);
displayScheduleSort.RemoveAt(0);
}
//Call the finalize process for creating the TableView
tableLoad.processTable(pageType, sortOrders, Cache, Request, Server, null, strmAllowed, null, null, true);
forcedScrollbar.InnerHtml = tableLoad.getForcedScrollBar();
CONTENTS.InnerHtml = tableLoad.getContents();
tableLoad.Dispose();
CONTENTS.Attributes.Add("onscroll", "fScroll(this)");
}
}
#endregion
//This is the routine used to filter out shows that do not match the recording type filter
private void checkRecordingType(ref int recordingTypeFilter, string text, int value)
{
ListItem item = recordingTypes.Items.FindByValue(value.ToString());
int flag = (int)Math.Pow(2, value);
if (item == null)
{
item = new ListItem(text, value.ToString());
recordingTypes.Items.Add(item);
item.Selected = (recordingTypeFilter & flag) != 0;
}
else
{
if (item.Selected)
recordingTypeFilter = recordingTypeFilter | flag;
else
recordingTypeFilter = recordingTypeFilter & (0xffff - flag);
}
}
protected void hlDelete_Click(object sender, System.EventArgs e)
{
//Create a new schedulehelper object to process all the found recordings (all types)
Schedule scheduleHelper = Global.Schedule;
foreach (string param in Request.Params.Keys)
{
if (param.StartsWith("item"))
{
ScheduledRecording scheduledRecording =
scheduleHelper.GetScheduledRecordingByOID(int.Parse(param.Substring(4)));
if (scheduledRecording != null)
{
scheduleHelper.CancelScheduledRecording(scheduledRecording);
}
}
}
}
#region Page Load code for the TreView - ProcessTree
//This is the main driver routine for loading the Treeview array
private void processTree(ProgrammeDisplay2 displayProgramme, Programme programme, ScheduledRecording scheduledRecording)
{
//Create a ProgrammeTreeItem to be loaded with the correct display information for the program
ProgramTreeItem treeItem = new ProgramTreeItem();
displayProgramme.FillProgrammeTreeArrayItem(treeItem, Server, programme, scheduledRecording, true, channel);
//Add the loaded ProgrammeTreeITem to the Array
pgmTree[treeIdx] = treeItem;
treeIdx = treeIdx + 1;
}
#endregion
#region Channel Icon procssing logic
private static string channelIconPath;
private static string[] channelIconExtensions;
public string GetChannelIcon(int channelNumber, string[] channelNames)
{
// Get the Channel Icon Directory
if (channelIconPath == null)
{
lock (typeof(Manage2))
{
if (channelIconPath == null)
{
channelIconPath = Path.Combine(Global.Settings.GetInstallDir(), @"media\ChannelLogos");
channelIconExtensions = Global.Settings.channelIconExtensions.Split(',');
}
}
}
Hashtable channelIconCache = (Hashtable)Cache["channelIconCache"];
if (channelIconCache == null)
{
lock (typeof(Manage2))
{
channelIconCache = (Hashtable)Cache["channelIconCache"];
if (channelIconCache == null)
{
channelIconCache = new Hashtable();
Cache.Add(
"channelIconCache",
channelIconCache,
new CacheDependency(channelIconPath),
DateTime.MaxValue,
Cache.NoSlidingExpiration,
CacheItemPriority.Normal,
null);
}
}
}
if (channelIconCache.ContainsKey(channelNumber))
{
return (string)channelIconCache[channelNumber];
}
lock (channelIconCache)
{
if (channelIconCache.ContainsKey(channelNumber))
{
return (string)channelIconCache[channelNumber];
}
string channelIconFile = null;
foreach (string channelName in channelNames)
{
foreach (string channelIconExtension in channelIconExtensions)
{
string cleanName = channelName;
while (cleanName.Contains("/"))
{
cleanName = channelName.Remove(channelName.IndexOf('/'), 1);
}
string probeFile = cleanName + "." + channelIconExtension;
if (File.Exists(Path.Combine(channelIconPath, probeFile)))
{
channelIconFile = probeFile;
break;
}
}
if (channelIconFile != null) break;
}
channelIconCache[channelNumber] = channelIconFile;
return channelIconFile;
}
}
#endregion
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
}
}